local extension = Package("heroes_ev2")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["heroes_ev2"] = "新约角色05-08",
  ["ev"] = "新约",
}

local altera = General(extension, "ev__altera", "ev", 4, 4, General.Female)

local junshenzhijian = fk.CreateTriggerSkill{
  name = "junshenzhijian",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = EV.getShortRoute(player, room:getPlayerById(data.to))
    for _, p in ipairs(targets) do
      if player.dead then break end
      if not p:isNude() then
        local cid = room:askForCardChosen(player, p, "he", self.name)
        if cid then
          room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
        end
      end
    end
  end,
}

local xingzhiwenzhang = fk.CreateTriggerSkill{
  name = "xingzhiwenzhang",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local cards = player.room:askForCard(player, 2, 2, false, self.name, true, tostring(Exppattern{ id = unshown }), "#xingzhiwenzhang")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:showCards(self.cost_data)
    if Fk:getCardById(self.cost_data[1]):compareColorWith(Fk:getCardById(self.cost_data[2]), false) then
      room:setPlayerMark(player, "xingzhiwenzhangdamage-turn", Fk:getCardById(self.cost_data[1]):getColorString())
    else
      room:addPlayerMark(player, "xingzhiwenzhangrange-turn", 2)
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and data.card:getColorString() == player:getMark("xingzhiwenzhangdamage-turn")
  end,
  on_refresh = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
}

local xingzhiwenzhang_attackrange = fk.CreateAttackRangeSkill{
  name = "#xingzhiwenzhang_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("xingzhiwenzhang") and from:getMark("xingzhiwenzhangrange-turn") > 0 then
      return from:getMark("xingzhiwenzhangrange-turn")
    end
  end,
}
xingzhiwenzhang:addRelatedSkill(xingzhiwenzhang_attackrange)
altera:addSkill(junshenzhijian)
altera:addSkill(xingzhiwenzhang)

Fk:loadTranslationTable{
  ["ev__altera"] = "阿蒂拉",
  ["designer:ev__altera"] = "KINGDOM43",
  ["junshenzhijian"] = "军神之剑",
  [":junshenzhijian"] = "当你使用【杀】指定唯一目标后，你可弃置你到其的短路径上的所有角色的各一张牌。",
  ["xingzhiwenzhang"] = "星之纹章",
  [":xingzhiwenzhang"] = "阶段技（始），你可展示两张手牌，若这些牌的颜色相同/不同，你于本回合内使用此颜色的【杀】造成的伤害+1/攻击范围+2。",
  ["#xingzhiwenzhang"] = "星之纹章：你可展示两张手牌",
}

local Alice = General(extension, "ev__alice", "ev", 3, 3, General.Female)

local shaonvwenle = fk.CreateTriggerSkill{
  name = "shaonvwenle",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  derived_piles = {"ev__renxing"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Play or event == fk.DamageInflicted)
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local ids = table.filter(player:getCardIds("he"), function (id) return EV.isSingleTarget(Fk:getCardById(id)) end)
      local cards = player.room:askForCard(player, 1, 999, true, self.name, true, tostring(Exppattern{ id = ids }), "#shaonvwenle-put")
      if #cards > 0 then
      self.cost_data = cards
      return true
      end
    else
      --local ids = table.filter(player:getPile("ev__renxing"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end)
      local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|ev__renxing|.|equip", "#shaonvwenle-discard", "ev__renxing")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      player:addToPile("ev__renxing", self.cost_data, true, self.name)
    else
      player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
      data.damage = data.damage - 1
    end
  end,
}

local xiaoxiaojunshi = fk.CreateViewAsSkill{
  name = "xiaoxiaojunshi",
  prompt = "你可明置一张与此“人形”类别或花色相同的手牌视为使用之",
  pattern = ".",
  interaction = function()
    local cards = table.filter(Self:getPile("ev__renxing"), function(id) return not table.contains(Self:getTableMark("@$xiaoxiaojunshi-round"), id) end)
    local all_names = table.map(cards, function(id) return Fk:getCardById(id).name end)
    local invoke_names = {}
    for _, name in ipairs(all_names) do
      if Fk:cloneCard(name).type == Card.TypeBasic or Fk:cloneCard(name):isCommonTrick() then
        table.insertIfNeed(invoke_names, name)
      end
    end
    if #invoke_names > 0 then
      return U.CardNameBox { choices = invoke_names }
    end
  end,
  enabled_at_play = function(self, player)
    return #player:getPile("ev__renxing") > 0
  end,
  enabled_at_response = function(self, player, response)
    return #player:getPile("ev__renxing") > 0 and not response
  end,
  card_filter = function(self, to_select, selected)
    if not self.interaction.data then return end
    local cards = table.filter(Self:getPile("ev__renxing"), function(id)
      return Fk:getCardById(id).name == self.interaction.data and not table.contains(Self:getTableMark("@$xiaoxiaojunshi-round"), id) end)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and Fk:getCardById(to_select):getMark("@@shown-inhand") == 0
    and table.find(cards, function(id) return Fk:getCardById(id).suit == Fk:getCardById(to_select).suit or Fk:getCardById(id).type == Fk:getCardById(to_select).type end)
  end,
  before_use = function (self, player, use)
    local room = player.room
    local show = use.card:getMark(self.name)
    if show ~= 0 and table.contains(player:getCardIds("h"), show) then
      EV.OpenCards(room, player, show, self.name)
      local mark = player:getTableMark("@$xiaoxiaojunshi-round")
      local cards = table.filter(player:getPile("ev__renxing"), function(id)
        return Fk:getCardById(id).name == use.card.name
        and (Fk:getCardById(id).suit == Fk:getCardById(show).suit or Fk:getCardById(id).type == Fk:getCardById(show).type) end)
      if #cards == 1 then
        table.insertIfNeed(mark, cards[1])
      else
        local get = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "请选择使用的人形")
        if #get > 0 then
          table.insertIfNeed(mark, get[1])
        else
          table.insertIfNeed(mark, cards[1])
        end
      end
      room:setPlayerMark(player, "@$xiaoxiaojunshi-round", mark)
    end
  end,
  view_as = function(self, cards)
    if not self.interaction.data or #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:setMark(self.name, cards[1])
    card.skillName = self.name
    return card
  end,
}

local huiguixuwu = fk.CreateTriggerSkill{
  name = "huiguixuwu",
  events = {fk.EventPhaseStart},
  --derived_piles = {"ev__renxing"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
    and table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
    and #table.map(table.filter(player.room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local n = player:getHandcardNum()
    local cards = player.room:askForCard(player, n, n, false, self.name, true, ".|.|.|ev__renxing", "#huiguixuwu-discard:::"..n, "ev__renxing")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
    --[[
    local tos, cards = player.room:askForChooseCardsAndPlayers(player, 1, 1, targets, n, n, ".|.|.|ev__renxing", "#huiguixuwu-discard:::"..n, self.name, true, true)
    if #tos > 0 and #cards > 0 then
      self.cost_data = {tos[1], cards}
      return true
    end]]
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #table.filter(self.cost_data, function (id) return Fk:getCardById(id).type == Card.TypeTrick end)
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
    if n > 0 then
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper)
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#huiguixuwu-choose", self.name, true)
      if #tos > 0 then
        room:damage({
          from = player,
          to = player.room:getPlayerById(tos[1]),
          damage = n,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}

Alice:addSkill(shaonvwenle)
Alice:addSkill(xiaoxiaojunshi)
Alice:addSkill(huiguixuwu)

Fk:loadTranslationTable{
  ["ev__alice"] = "爱丽丝",
  ["designer:ev__alice"] = "KINGDOM43",
  ["shaonvwenle"] = "少女文乐",
  [":shaonvwenle"] = "阶段技（始），你可将任意张目标唯一的牌置于角色牌上，称为“人形”。当你受到伤害时，你可弃“人形”中的一张装备牌，令此伤害-1。",
  ["#shaonvwenle-put"] = "你可将任意张目标唯一的牌置于角色牌上",
  ["#shaonvwenle-discard"] = "你可弃“人形”中的一张装备牌，令此伤害-1。",
  ["ev__renxing"] = "人形",
  ["xiaoxiaojunshi"] = "小小军势",
  [":xiaoxiaojunshi"] = "当你需要使用“人形”中的基础牌或即时魔法牌时，若你于本轮内未使用过此“人形”，你可明置一张与之类别或花色相同的手牌，视为使用之。",
  ["@$xiaoxiaojunshi-round"] = "此轮已用",
  ["huiguixuwu"] = "回归虚无",
  [":huiguixuwu"] = "结束阶段，若你的所有手牌均已明置，你可弃等同于手牌数张“人形”，对你攻击范围内的一名角色造成X点伤害（X为这些“人形”中魔法牌的数量）。",
  ["#huiguixuwu-discard"] = "你可弃%arg张“人形",
  ["#huiguixuwu-choose"] = "选择你攻击范围内的一名角色",
}

local Hassan = General(extension, "ev__hassen", "ev", 3, 3, General.Bigender)

local wangxianghuanxiang_trigger = fk.CreateTriggerSkill{
  name = "#wangxianghuanxiang",
  events = {fk.RoundStart, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return event == fk.RoundStart or (event == fk.Damaged and target == player)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.Damaged then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local all_names = U.getAllCardNames("bt")
      local names = table.simpleClone(all_names)
      for _, name in ipairs(all_names) do
        if table.contains(player:getTableMark("@$wangxianghuanxiang"), name) then
          table.removeOne(names, name)
        end
      end
      room:setPlayerMark(player, "wangxianghuanxiang_names", names)
    else
      local mark = player:getTableMark("wangxianghuanxiang_names")
      local names = player:getTableMark("@$wangxianghuanxiang")
      for _, name in ipairs(names) do
        if table.contains(mark, name) then
          table.removeOne(mark, name)
        end
      end
      if #mark > 0 then
        local choice = room:askForChoice(player, mark, self.name, "#wangxianghuanxiang-remove")
        if string.find(choice, "slash") then
          local all_names = U.getAllCardNames("bt")
          for _, name in ipairs(all_names) do
            if string.find(name, "slash") then
              table.insertIfNeed(names, name)
            end
          end
        else
          table.insertIfNeed(names, choice)
        end
        room:setPlayerMark(player, "@$wangxianghuanxiang", names)
      end
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return data.card.skillName == "wangxianghuanxiang" and #TargetGroup:getRealTargets(data.tos) > 1
      and string.find(Fk:translate(":"..data.card.name), Fk:translate("all"))
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local all_targets = table.simpleClone(TargetGroup:getRealTargets(data.tos))
    local t = player.room:askForChoosePlayers(player, all_targets, 1, 1, "#wangxianghuanxiang-choose", self.name, false)
    data.tos = {}
    TargetGroup:pushTargets(data.tos, t[1])
  end,
}

local wangxianghuanxiang = fk.CreateViewAsSkill{
  name = "wangxianghuanxiang",
  pattern = ".",
  --prompt = "#ls__junshi",
  interaction = function(self)
    local names = Self:getTableMark("wangxianghuanxiang_names")
    if #names == 0 then return false end
    return U.CardNameBox { choices = names }
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not response
  end,
}

wangxianghuanxiang:addRelatedSkill(wangxianghuanxiang_trigger)
Hassan:addSkill(wangxianghuanxiang)

Fk:loadTranslationTable{
  ["ev__hassen"] = "百貌哈桑",
  ["designer:ev__hassen"] = "zengyouyu",
  ["wangxianghuanxiang"] = "妄想幻象",
  ["#wangxianghuanxiang"] = "妄想幻象",
  [":wangxianghuanxiang"] = "每轮开始时，你可声明任意张除{ }外的基础牌或即时魔法牌；回合技，你可将一张手牌当你于本轮声明的牌使用，此牌使用目标中的“所有”改为“一名”；当你受到伤害后，你为{ }里添加你于本轮声明的一张牌的牌名。<br>"
  .."<font color='gray'>注：为便于代码实现，每轮开始时改为声明所有能声明的牌名</font>",
  ["#wangxianghuanxiang-remove"] = "请选择一个牌名，本局游戏无法再声明",
  ["@$wangxianghuanxiang"] = "已添加",
  ["all"] = "所有",
  ["#wangxianghuanxiang-choose"] = "请选择此牌的唯一目标",
}

local Bedivere = General(extension, "ev__bedivere", "ev", 4)

local ev__guijian = fk.CreateTriggerSkill{
  name = "ev__guijian",
  anim_type = "switch",
  switch_skill_name = "ev__guijian",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      local ids = {}
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local end_id = turn_event.id
      U.getEventsByRule(room, GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from and move.moveReason == fk.ReasonDiscard 
          and ((move.from == target.id and player:getSwitchSkillState(self.name, false) == fk.SwitchYang)
          or (move.from == player.id and player:getSwitchSkillState(self.name, false) == fk.SwitchYin)) then
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(ids, info.cardId)
            end
          end
        end
        return false
      end, end_id)
      return #ids > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#ev__guijian-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
    local end_id = turn_event.id
    U.getEventsByRule(room, GameEvent.MoveCards, 999, function (e)
      for _, move in ipairs(e.data) do
        if move.from and move.moveReason == fk.ReasonDiscard 
        and ((move.from == target.id and player:getSwitchSkillState(self.name, true) == fk.SwitchYang)
        or (move.from == player.id and player:getSwitchSkillState(self.name, true) == fk.SwitchYin)) then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      return false
    end, end_id)
    local cards = table.simpleClone(ids)
    for _, id in ipairs(cards) do
      if room:getCardArea(id) ~= Card.DiscardPile then
        table.removeOne(ids, id)
      end
    end
    if #ids > 0 then
      if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
        room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
        EV.OpenCards(room, player, ids, self.name)
      else
        room:moveCardTo(ids, Card.PlayerHand, room:getPlayerById(self.cost_data), fk.ReasonJustMove, self.name, "", true)
        room:loseHp(player, 1, self.name)
      end
    end
  end,
}

local ev__yinwan_act = fk.CreateActiveSkill{
  name = "ev__yinwan_act",
  anim_type = "offensive",
  min_card_num = 1,
  min_target_num = 1,
  can_use = Util.FalseFunc,
  card_filter = function(self, to_select)
    return Fk:getCardById(to_select):getMark("@@shown-inhand") > 0
  end,
  target_filter = function(self, to_select, selected)
    local to = Fk:currentRoom():getBanner("ev__yinwan")
    local target = Fk:currentRoom():getPlayerById(to_select)
    return Fk:currentRoom():getPlayerById(to):distanceTo(target) <= 1 and not target:isAllNude()
  end,
  feasible = function(self, selected, selected_cards)
    return #selected == #selected_cards and #selected > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true)
    for _, p in ipairs(effect.tos) do
      local target = room:getPlayerById(p)
      if not target.dead and not target:isNude() then
        local cid = room:askForCardChosen(player, target, "hej", self.name)
        if cid then
          room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
        end
      end
    end
  end,
}

local ev__yinwan = fk.CreateTriggerSkill{
  name = "ev__yinwan",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setBanner("ev__yinwan", data.to)
    player.room:askForUseActiveSkill(player, "ev__yinwan_act", "#ev__yinwan", true)
    player.room:setBanner("ev__yinwan", 0)
  end,
}

local yinwan_maxcards = fk.CreateMaxCardsSkill{
  name = "#ev__yinwan_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill(self) and card:getMark("@@shown-inhand") > 0
  end,
}

Fk:addSkill(ev__yinwan_act)
ev__yinwan:addRelatedSkill(yinwan_maxcards)
Bedivere:addSkill(ev__guijian)
Bedivere:addSkill(ev__yinwan)

Fk:loadTranslationTable{
  ["ev__bedivere"] = "贝狄威尔",
  ["designer:ev__bedivere"] = "夜之礼赞",
  ["ev__guijian"] = "归剑",
  [":ev__guijian"] = "转换技，一名角色的回合结束时，你可：①获得弃牌堆里其于此回合内因弃置而失去过的牌，你明置这些牌；②令一名其他角色获得弃牌堆里你于此回合内因弃置而失去过的牌，然后你失去1点体力。",
  ["#ev__guijian-choose"] = "归剑：你可以令一名角色获得你此回合弃置的牌",
  ["ev__yinwan"] = "银腕",
  ["ev__yinwan_act"] = "银腕",
  ["#ev__yinwan"] = "你可弃置任意张明置手牌和目标角色距离1以内的等量名角色各一张牌",
  [":ev__yinwan"] = "你的明置手牌不计入手牌上限。当你使用【杀】指定一个目标后，你可弃置任意张明置手牌，弃置其距离1以内的等量名角色区域里的各一张牌。",
}

local Nightingale = General(extension, "ev__nightingale", "ev", 4, 4, General.Female)

local rentilijie = fk.CreateTriggerSkill{
  name = "rentilijie",
  mute = true,
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.card.type == Card.TypeBasic then
      if event == fk.TargetConfirmed then
        return table.find(player:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      else
        local to = player.room:getPlayerById(data.to)
        return table.find(to:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      local ids = table.filter(player:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      local cards = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#rentilijie-cancel:::"..data.card:toLogString())
      if #cards > 0 then
        self.cost_data = cards[1]
        return true
      end
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#rentilijie:::"..data.card:toLogString())
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
    else
      data.disresponsive = true
    end
  end,
}

local gangzhikanhu = fk.CreateTriggerSkill{
  name = "gangzhikanhu",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#gangzhikanhu::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_choices = {"gangzhikanhu1","gangzhikanhu2"}
    local choices = {}
    if #target:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and #target:getAvailableEquipSlots(Card.SubtypeArmor) > 0 then
      table.insert(choices, all_choices[1])
    end
    table.insert(choices, all_choices[2])
    local choice = room:askForChoice(target, choices, self.name, "", false, all_choices)
    if choice == all_choices[1] then
      room:abortPlayerArea(target, {"WeaponSlot", "ArmorSlot"})
    else
      room:changeMaxHp(target, -1)
    end
    if not target.dead then
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

Nightingale:addSkill(rentilijie)
Nightingale:addSkill(gangzhikanhu)

Fk:loadTranslationTable{
  ["ev__nightingale"] = "南丁格尔",
  ["designer:ev__nightingale"] = "KINGDOM43",
  ["rentilijie"] = "人体理解",
  [":rentilijie"] = "当你指定/成为基础牌的一个目标后，若其/你有与此牌花色相同的手牌，你可令其不能对此牌使用牌/弃置一张与此牌花色相同的手牌，令此牌无效。",
  ["#rentilijie"] = "你可令%arg不可被响应",
  ["#rentilijie-cancel"] = "你可弃置一张与%arg花色相同的手牌令此%arg无效",
  ["gangzhikanhu"] = "钢之看护",
  [":gangzhikanhu"] = "轮次技，当一名角色处于濒死状态时，你可令其选择一项：1.废除武器栏与防具栏；2.减少1点体力上限。选择完毕后，其回复1点体力。",
  ["#gangzhikanhu"] = "钢之看护：你可令%dest回复1点体力",
  ["gangzhikanhu1"] = "废除武器栏与防具栏",
  ["gangzhikanhu2"] = "减少1点体力上限",
}

local Suika = General(extension, "ev__suika", "ev", 4, 4, General.Female)
local SPSuika = General(extension, "ev_sp__suika", "ev", 4, 4, General.Female)

local ev__jvshu = fk.CreateActiveSkill{
  name = "ev__jvshu",
  anim_type = "support",
  prompt = "你可弃置至少一张手牌并增加等量点体力上限",
  min_card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    room:changeMaxHp(player, #effect.cards)
  end,
}

local ev__jvshu_lose = fk.CreateActiveSkill{
  name = "ev__jvshu_lose",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  interaction = function()
    return UI.Spin {
      from = 1,
      to = Self.maxHp,
    }
  end,
  can_use = Util.FalseFunc,
  on_use = function(self, room, effect)
    if not self.interaction.data then return end
    local player = room:getPlayerById(effect.from)
    local tolose = self.interaction.data
    room:changeMaxHp(player, 0 - tolose, self.name)
    if player.dead then return end
    player:drawCards(tolose, self.name)
  end,
}

local jvshu_trigger = fk.CreateTriggerSkill{
  name = "#jvshu_trigger",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "ev__jvshu_lose", "#jvshu-invoke", true)
    if dat then
      if data.card.trueName == "slash" and table.every(player.room:getOtherPlayers(player), function (p) return p.maxHp > player.maxHp end) then
        EV.nullifiedCard(data, data.card, player)
      end
    end
  end,
}

local ev__huaisui = fk.CreateTriggerSkill{
  name = "ev__huaisui",
  events = {fk.DamageCaused},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      return player.room:getBanner("ev__huaisui"..player.id) and player.maxHp > player.room:getBanner("ev__huaisui"..player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = player.room:getBanner("ev__huaisui"..player.id) - player.maxHp
    player.room:changeMaxHp(player, n, self.name)
    n = math.min(-n, #data.to:getCardIds("he"))
    if n > 0 then
      local cards = player.room:askForCardsChosen(player, data.to, n, n, "he", self.name)
      if n == #data.to:getCardIds("he") then
        data.damage = data.damage + 1
      end
      player.room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, false, player.id)
    end
  end,

  refresh_events = {fk.EventAcquireSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.name == self.name
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setBanner("ev__huaisui"..player.id, player.maxHp)
  end,
}


Fk:addSkill(ev__jvshu_lose)
ev__jvshu:addRelatedSkill(jvshu_trigger)
Suika:addSkill(ev__jvshu)
Suika:addSkill(ev__huaisui)

local ev__cuimeng = fk.CreateTriggerSkill{
  name = "ev__cuimeng",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not p:isNude() then
        local card = room:askForCard(p, 1, 1, true, self.name, false, ".", "#cuimeng-give::"..player.id)
        if #card > 0 then
          room:obtainCard(player.id, card[1], false, fk.ReasonGive)
          table.insert(cards, card[1])
        end
      end
    end
    cards = table.filter(cards, function (id) return room:getCardOwner(id) == player end)
    room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
    room:useVirtualCard("banquet", nil, player, room.alive_players, self.name, true)
  end,
}

SPSuika:addSkill(ev__cuimeng)

Fk:loadTranslationTable{
  ["ev__suika"] = "伊吹萃香",
  ["ev_sp__suika"] = "伊吹萃香",
  ["designer:ev__suika"] = "KINGDOM43",
  ["designer:ev_sp__suika"] = "KINGDOM43",
  ["ev__jvshu"] = "聚疏",
  [":ev__jvshu"] = "出牌阶段，你可弃置至少一张手牌并增加等量点体力上限。当你成为牌的目标后，你可减少至少1点体力上限并摸等量张牌，然后若此牌为【杀】且你为体力上限唯一最小的角色，此牌对你无效。",
  ["#jvshu_trigger"] = "聚疏",
  ["#jvshu-invoke"] = "聚疏：你可减少至少1点体力上限并摸等量张牌",
  ["ev__jvshu_lose"] = "聚疏",
  ["ev__huaisui"] = "坏碎",
  [":ev__huaisui"] = "当你使用【杀】造成伤害时，你可将体力上限减少至初始值，弃置受伤角色的等同于减少值张牌；若你以此法弃置其所有牌，则此伤害+1。",

  ["ev__cuimeng"] = "萃梦",
  [":ev__cuimeng"] = "准备阶段，你可令所有其他角色各将一张牌交给你，然后你将这些牌置于牌堆顶，视为使用【欢饮酒宴】。",
  ["#cuimeng-give"] = "萃梦：请选择交给%dest的牌",
}

local xiahoudun = General(extension, "ev__xiahoudun", "ev", 4, 4, General.Female)

local nufachongtian = fk.CreateTriggerSkill{
  name = "nufachongtian",
  events = {fk.Damage, fk.Damaged},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.Damage then
        return data.to:isAlive() and not data.to:isNude()
      else
        return data.from and not player:isNude()
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.Damage then
      return player.room:askForSkillInvoke(player, self.name, nil, "#nufachongtian-invoke::"..data.to.id)
    else
      local cards = player.room:askForDiscard(player, 2, 2, true, self.name, true, ".", "#nufachongtian-throw::"..data.from.id)
      return #cards > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      local id = room:askForCardChosen(player, data.to, "he", self.name)
      if id then
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    else
      room:damage({
        from = player,
        to = data.from,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local baishidanjing = fk.CreateTriggerSkill{
  name = "baishidanjing",
  frequency = Skill.Limited,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      for _, move in ipairs(data) do
        if move.from == player.id and move.skillName == "nufachongtian" then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return player:isKongcheng() or table.every(player:getCardIds("h"), function (id)
                return Fk:getCardById(id).color ~= Card.Red
              end)
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, player.hp, "#baishidanjing:::"..player.hp, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player:isKongcheng() then
      player:showCards(player:getCardIds("h"))
    end
    for _, p in ipairs(self.cost_data) do
      p = room:getPlayerById(p)
      if p.maxHp > p:getHandcardNum() then
        p:drawCards(p.maxHp - p:getHandcardNum(), self.name)
      end
    end
  end,
}

xiahoudun:addSkill(nufachongtian)
xiahoudun:addSkill(baishidanjing)

Fk:loadTranslationTable{
  ["ev__xiahoudun"] = "春兰",
  ["designer:ev__xiahoudun"] = "轮回中听琴",
  ["nufachongtian"] = "怒发冲天",
  [":nufachongtian"] = "当你造成伤害后，你可弃置受伤角色的一张牌。当你受到伤害后，你可弃置两张牌，对伤害来源造成1点伤害。",
  ["#nufachongtian-invoke"] = "你可弃置%dest的一张牌",
  ["#nufachongtian-throw"] = "你可弃置两张牌，对%dest造成1点伤害",
  ["baishidanjing"] = "拔矢啖睛",
  [":baishidanjing"] = "限定技，当你因【怒发冲天】而失去牌后，若你没有红色手牌，则你可展示所有手牌，令至多X名角色将手牌补至其体力上限（X为你的体力值）。",
  ["#baishidanjing"] = "你可令至多%arg名角色将手牌补至其体力上限",
}

local Enqidu = General(extension, "ev__enqidu", "ev", 4)

local ev__bianrong = fk.CreateTriggerSkill{
  name = "ev__bianrong",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 7
    local choices = {"1","2","3"}
    local draws = room:askForChoice(player, choices, self.name, "#bianrong_draw", false, {"1","2","3"})
    num = num - tonumber(draws)
    if num > 4 then
      table.removeOne(choices, "1")
      if num > 5 then
        table.removeOne(choices, "2")
      end
    end
    local slashs = room:askForChoice(player, choices, self.name, "#bianrong_slash", false, {"1","2","3"})
    num = num - tonumber(slashs)
    room:setPlayerMark(player, "@ev__bianrong", {tonumber(draws), tonumber(slashs), num})
  end,

  refresh_events = {fk.DrawNCards},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("@ev__bianrong") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.n = player:getMark("@ev__bianrong")[1]
  end,
}

local bianrong_slash = fk.CreateTargetModSkill{
  name = "#ev__bianrong_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("ev__bianrong") and skill.trueName == "slash_skill" and card.trueName == "slash"
    and scope == Player.HistoryPhase and player:getMark("@ev__bianrong") ~= 0 then
      return player:getMark("@ev__bianrong")[2] - 1
    end
  end,
}

local bianrong_maxcards = fk.CreateMaxCardsSkill{
  name = "#ev__bianrong_maxcards",
  fixed_func = function (self, player)
    if player:hasSkill("ev__bianrong") and player:getMark("@ev__bianrong") ~= 0 then
      return player:getMark("@ev__bianrong")[3]
    end
  end,
}

local ev__tianzhisuo = fk.CreateActiveSkill{
  name = "ev__tianzhisuo",
  anim_type = "support",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(player, "@@ev__tianzhisuo")
    room:addPlayerMark(target, "@@ev__tianzhisuo")
    player:setChainState(true)
    target:setChainState(true)
    --room:setBanner("ev__tianzhisuo", {effect.from, effect.tos[1]})
  end,
}

local tianzhisuo_trigger = fk.CreateTriggerSkill{
  name = "#tianzhisuo_trigger",
  mute = true,
  events = {fk.TargetSpecified, fk.TargetConfirmed, fk.TurnStart, fk.BeforeChainStateChange},
  can_trigger = function(self, event, target, player, data)
    if target:getMark("@@ev__tianzhisuo") > 0 and player:hasSkill(self.name) then
      if event == fk.TargetSpecified or event == fk.TargetConfirmed then
        return player ~= target and data.card.trueName == "slash"
      elseif event == fk.TurnStart then
        return player ~= target
      else
        return target.chained
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified or event == fk.TargetConfirmed then
      return player.room:askForSkillInvoke(player, self.name, nil, "#tianzhisuo-slash:::"..data.card:toLogString())
    elseif event == fk.TurnStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "#tianzhisuo-hands::"..target.id..":"..player:getMaxCards())
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified or event == fk.TargetConfirmed then
      room:loseHp(player, 1, self.name)
      data.nullifiedTargets = AimGroup:getAllTargets(data.tos)
    elseif event == fk.TurnStart then
      local n = player:getMaxCards() - target:getHandcardNum()
      if n > 0 then
        target:drawCards(n, self.name)
      elseif n < 0 then
        room:askForDiscard(target, -n, -n, false, self.name, false)
      end
    else
      return true
    end
  end,
}

ev__bianrong:addRelatedSkill(bianrong_slash)
ev__bianrong:addRelatedSkill(bianrong_maxcards)
ev__tianzhisuo:addRelatedSkill(tianzhisuo_trigger)
Enqidu:addSkill(ev__bianrong)
Enqidu:addSkill(ev__tianzhisuo)

Fk:loadTranslationTable{
  ["ev__enqidu"] = "恩奇都",
  ["designer:ev__enqidu"] = "KINGDOM43",
  ["ev__bianrong"] = "变容",
  ["@ev__bianrong"] = "变容",
  [":ev__bianrong"] = "锁定技，准备阶段，你将共计7点数值重新分配给以下项（每项初始为0，至多为3）：1.摸牌阶段摸牌数；2.使用【杀】的次数上限；3.手牌上限。",
  ["#bianrong_draw"] = "请分配摸牌阶段摸牌数",
  ["#bianrong_slash"] = "请分配使用【杀】的次数上限",
  ["ev__tianzhisuo"] = "天之锁",
  [":ev__tianzhisuo"] = "限定技，出牌阶段，你可选择一名其他角色，令你与其始终横置。若如此做，其回合开始时，你可令其将手牌摸或弃置至你的手牌上限；且当其指定或成为【杀】的目标后，你可失去1点体力，令此【杀】无效。",
  ["@@ev__tianzhisuo"] = "<font color=\"#B4C424\">天之锁</font>",
  ["#tianzhisuo_trigger"] = "天之锁",
  ["#tianzhisuo-slash"] = "你可失去1点体力令%arg无效",
  ["#tianzhisuo-hands"] = "你可令%dest将手牌摸或弃置至%arg张",
}

local Gondor = General(extension, "ev__gondor", "ev", 3)

local zhuizongshu_act = fk.CreateActiveSkill{
  name = "zhuizongshu_act",
  anim_type = "offensive",
  min_card_num = 1,
  min_target_num = 1,
  can_use = Util.FalseFunc,
  card_filter = function(self, to_select)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = Util.TrueFunc,
  feasible = function(self, selected, selected_cards)
    return #selected == #selected_cards and #selected > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true)
    local mark = player:getTableMark("zhuizongshu")
    for _, p in ipairs(effect.tos) do
      table.insert(mark, p)
      room:addPlayerMark(room:getPlayerById(p), "@@zhuizongshu")
    end
    room:setPlayerMark(player, "zhuizongshu", mark)
  end,
}

local zhuizongshu = fk.CreateTriggerSkill{
  name = "zhuizongshu",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseEnd then
      return player:hasSkill(self) and target == player and player.phase == Player.Play
    else
      return player:hasSkill(self) and data.from and EV.isFriend(player, data.from) and data.to:getMark("@@zhuizongshu") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseEnd then
      local success, _ = player.room:askForUseActiveSkill(player, "zhuizongshu_act", "#zhuizongshu", true) 
      return success
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      data.from:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.EventPhaseEnd, fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true, true) and target == player and (player.phase == Player.Play or event == fk.Deathed)
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room.alive_players) do
      if table.contains(player:getTableMark("zhuizongshu"), p.id) or event == fk.Deathed then
        player.room:setPlayerMark(p, "@@zhuizongshu", 0)
      end
    end
  end,
}

local anyingbu_viewas = fk.CreateViewAsSkill{
  name = "anyingbu_viewas",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    if #selected > 0 then return false end
    return Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ev__slash")
    card.skillName = "anyingbu"
    card:addSubcard(cards[1])
    return card
  end,

  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return not response
  end,
}

local anyingbu = fk.CreateTriggerSkill{
  name = "anyingbu",
  mute = true,
  events = {fk.EventPhaseStart, fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player.phase == Player.Finish and player:hasSkill(self) and
      #player.room.logic:getEventsOfScope(GameEvent.UseCard, 998, function(e)
        local use = e.data[1]
        return use.from == player.id
      end, Player.HistoryTurn) >= player.hp
    else
      return target == player and player:hasSkill(self) and player:getMark("anyingbu-turn") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      local success, dat = player.room:askForUseActiveSkill(player, "anyingbu_viewas", "#anyingbu-slash", true)
      if success then
        self.cost_data = dat
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:addPlayerMark(player, "@@anyingbu_buff")
    else
      room:setPlayerMark(player, "anyingbu-turn", 0)
      room:notifySkillInvoked(player, self.name, "offensive")
      local card = Fk.skills["anyingbu_viewas"]:viewAs(self.cost_data.cards)
      room:useCard{
        from = player.id,
        tos = table.map(self.cost_data.targets, function(id) return {id} end),
        card = card,
        extraUse = true,
      }
    end
  end,

  refresh_events = {fk.BeforeTurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("@@anyingbu_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@anyingbu_buff", 0)
    player.room:addPlayerMark(player, "anyingbu-turn")
  end,
}

local anyingbu_prohibit = fk.CreateProhibitSkill{--锁攻击范围优先级低，限制使用杀的目标
  name = "#anyingbu_prohibit",
  is_prohibited = function(self, from, to, card)
    if card.trueName == "slash" and to:hasSkill(self) then
      return to:getMark("@@anyingbu_buff") > 0
    end
  end,
}

local anyingbu_targetmod = fk.CreateTargetModSkill{
  name = "#anyingbu_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, "anyingbu")
  end,
}

Fk:addSkill(zhuizongshu_act)
Fk:addSkill(anyingbu_viewas)
anyingbu:addRelatedSkill(anyingbu_prohibit)
anyingbu:addRelatedSkill(anyingbu_targetmod)
Gondor:addSkill(zhuizongshu)
Gondor:addSkill(anyingbu)

Fk:loadTranslationTable{
  ["ev__gondor"] = "刚铎",
  ["designer:ev__gondor"] = "路人orz",
  ["zhuizongshu"] = "追踪术",
  ["zhuizongshu_act"] = "追踪术",
  ["@@zhuizongshu"] = "追踪术",
  ["#zhuizongshu"] = "你可弃置任意张手牌并选择等量名角色",
  [":zhuizongshu"] = "出牌阶段结束时，你可弃置任意张手牌并选择等量名角色，则直至你的下个出牌阶段结束：当己方角色对这些角色造成伤害时，伤害来源摸一张牌。",
  ["anyingbu"] = "暗影步",
  ["@@anyingbu_buff"] = "暗影步",
  ["anyingbu_viewas"] = "暗影步",
  [":anyingbu"] = "结束阶段，若你于本回合内使用过的牌数不小于体力值，你不是【杀】的合法目标直至你的下回合开始；且你的下回合开始时，你可将一张黑色牌当【杀】使用（无距离限制）。",
  ["#anyingbu-slash"] = "你可将一张黑色牌当【杀】使用",
}

local Miyamoto = General(extension, "ev__miyamoto", "ev", 4, 4, General.Female)

local tianyan_buff = fk.CreateTriggerSkill{
  name = "#ev__tianyan_buff",
  anim_type = "offensive",

  refresh_events = {fk.HandleAskForPlayCard},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and data.eventData and data.eventData.from == player.id
    and data.eventData.card and data.eventData.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if not data.afterRequest then
      room:setBanner("ev__tianyan_record", data.eventData.card:getColorString())
    else
      room:setBanner("ev__tianyan_record", 0)
    end
  end,
}

local tianyan_prohibit = fk.CreateProhibitSkill{
  name = "#ev__tianyan_prohibit",
  prohibit_use = function(self, player, card)
    local room = Fk:currentRoom()
    local colorStr = room:getBanner("ev__tianyan_record")
    if colorStr and colorStr ~= 0 then
      return card and card.name == "ev__jink" and (card.color == Card.NoColor or card:getColorString() ~= colorStr)
    end
  end,
}

local ev__tianyan = fk.CreateViewAsSkill{
  name = "ev__tianyan",
  pattern = "slash,jink",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local _c = Fk:getCardById(to_select)
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("ev__jink")
    elseif _c.trueName == "jink" then
      c = Fk:cloneCard("ev__slash")
    else
      return false
    end
    return (Fk.currentResponsePattern == nil and Self:canUse(c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local _c = Fk:getCardById(cards[1])
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("ev__jink")
    elseif _c.trueName == "jink" then
      c = Fk:cloneCard("ev__slash")
    end
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}

local ev__wulun = fk.CreateTriggerSkill{
  name = "ev__wulun",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Finish and #player:getTableMark("@ev__wulun-suit") >= 4
      else
        return data.card.trueName == "slash" and #player:getTableMark("@$ev__wulun-name") >= 7
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      U.askForUseVirtualCard(room, player, "ev__slash", nil, self.name, nil, true)
    else
      local to = room:getPlayerById(data.to)
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if use_event == nil then return end
      room:addPlayerMark(to, fk.MarkArmorNullified)
      use_event:addCleaner(function()
        room:removePlayerMark(to, fk.MarkArmorNullified)
      end)
    end
  end,

  refresh_events = {fk.CardUsing, fk.CardResponding},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local suit = data.card:getSuitString(true)
    local name = data.card.name
    if string.find(name, "__slash") then name = "ev__slash" end--不能用truename否则出现三国杀的牌
    local record = player:getTableMark("@ev__wulun-suit")
    local names = player:getTableMark("@$ev__wulun-name")
    if suit ~= "nosuit" then
      table.insertIfNeed(record, suit)
    end
    table.insertIfNeed(names, name)
    room:setPlayerMark(player, "@ev__wulun-suit", record)
    room:setPlayerMark(player, "@$ev__wulun-name", names)
  end,
}

local ev__wulun_tar = fk.CreateTargetModSkill{
  name = "#ev__wulun_targetmod",
  distance_limit_func =  function(self, player, skill, card)
    if player:hasSkill(self) and card and card.trueName == "slash" and #player:getTableMark("@$ev__wulun-name") >= 7 then
      return 999
    end
  end,
}

ev__tianyan:addRelatedSkill(tianyan_buff)
ev__tianyan:addRelatedSkill(tianyan_prohibit)
ev__wulun:addRelatedSkill(ev__wulun_tar)
Miyamoto:addSkill(ev__tianyan)
Miyamoto:addSkill(ev__wulun)

Fk:loadTranslationTable{
  ["ev__miyamoto"] = "宫本武藏",
  ["designer:ev__miyamoto"] = "KINGDOM43",
  ["ev__tianyan"] = "天眼",
  ["#ev__tianyan_prohibit"] = "天眼",
  [":ev__tianyan"] = "锁定技，你使用的【杀】不是与之颜色不同的【闪】的合法目标。当你需要使用或打出【杀】/【闪】时，你的【闪】/【杀】均视为【杀】/【闪】。<br>"
  .."<font color='gray'>注：为便于代码实现，后半段效果改为杀闪相互转化（即龙胆）</font>",
  ["ev__wulun"] = "五轮",
  [":ev__wulun"] = "若你使用或打出过的牌含有：四种花色，你可于结束阶段视为使用【杀】；七种牌名，你使用的【杀】无距离限制且无视防具。",
  ["@ev__wulun-suit"] = "花色",
  ["@$ev__wulun-name"] = "牌名",
}

local Yagyuu = General(extension, "ev__yagyuu", "ev", 4)

local wudaoqu = fk.CreateTriggerSkill{
  name = "wudaoqu",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "slash" and (data.from == player.id or data.to == player.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.from)
    if data.from == player.id then
      from = room:getPlayerById(data.to)
    end
    local all_choices = {"wudaoqu1", "wudaoqu2"}
    local choices = {}
    if from:isAlive() and from:getEquipment(Card.SubtypeWeapon) then
      table.insert(choices, "wudaoqu1")  
    end
    if data.to == player.id and room:getCardArea(data.card) == Card.Processing then
      table.insert(choices, "wudaoqu2")
    end
    if #choices > 0 then
      local choice = room:askForChoice(player, choices, self.name, "", false, all_choices)
      if choice == "wudaoqu1" then
        room:moveCardTo(from:getEquipment(Card.SubtypeWeapon), Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, player.id)
      else
        room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true, player.id)
      end
    end
  end,
}

local jianchanyiru = fk.CreateTriggerSkill{
  name = "jianchanyiru",
  anim_type = "switch",
  switch_skill_name = "jianchanyiru",
  events = {fk.EventPhaseStart, fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player:getSwitchSkillState(self.name, false) == fk.SwitchYang and player.phase == Player.Start
      else
        if player:getSwitchSkillState(self.name, false) == fk.SwitchYin and data.to == Player.Discard then
          local play_ids = {}
          player.room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
            if e.data[2] == Player.Play and e.end_id then
              table.insert(play_ids, {e.id, e.end_id})
            end
            return false
          end, Player.HistoryTurn)
          if #play_ids == 0 then return true end
          local function PlayCheck (e)
            local in_play = false
            for _, ids in ipairs(play_ids) do
              if e.id > ids[1] and e.id < ids[2] then
                in_play = true
                break
              end
            end
            return in_play and e.data[1].from == player.id and e.data[1].tos
            and table.find(TargetGroup:getRealTargets(e.data[1].tos), function(pid) return pid ~= player.id end)
          end
          return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, PlayCheck, Player.HistoryTurn) == 0
          and player:getMark("jianchanyiru-turn") > 0
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return U.askForUseVirtualCard(player.room, player, "ev__slash", nil, self.name,
      "#jianchanyiru-slash", true, true, false, true)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
    else
      return true
    end
  end,

  refresh_events = {fk.DamageCaused, fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      return player:hasSkill(self) and target == player and data.card.skillName == self.name
      and data.to and data.to.hp >= player.hp
    else
      return player:hasSkill(self) and target == player and player.phase == Player.Play
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      data.damage = data.damage + 1
    else
      player.room:addPlayerMark(player, "jianchanyiru-turn")
    end
  end,
}

Yagyuu:addSkill(wudaoqu)
Yagyuu:addSkill(jianchanyiru)

Fk:loadTranslationTable{
  ["ev__yagyuu"] = "柳生宗矩",
  ["designer:ev__yagyuu"] = "豪曹",
  ["wudaoqu"] = "无刀取",
  [":wudaoqu"] = "当你/其他角色使用【闪】抵消其他角色/你使用的【杀】时，你可选择一项：1.获得其装备区里的武器牌；2.获得以你为目标的此【杀】。",
  ["wudaoqu1"] = "获得其装备区里的武器牌",
  ["wudaoqu2"] = "获得以你为目标的此【杀】",
  ["jianchanyiru"] = "剑禅一如",
  [":jianchanyiru"] = "转换技：阳：准备阶段，你可视为使用【杀】；当此【杀】造成伤害时，若受伤角色的体力值不小于你，则此伤害+1；阴：若你于本回合的出牌阶段内使用过牌且这些牌的目标仅含有你，你跳过弃牌阶段。",
  ["#jianchanyiru-slash"] = "剑禅一如：你可视为使用【杀】",
}

local chengong = General(extension, "ev__chengong", "ev", 3, 3, General.Female)

local yishengxuanming = fk.CreateTriggerSkill{
  name = "yishengxuanming",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
      local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#yishengxuanming-choose", self.name, false)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    to:drawCards(2, self.name)
    local use = room:askForUseCard(to, "slash", "slash", "#yishengxuanming-slash:"..player.id, true,
    { bypass_distances = false, bypass_times = true })
    if use then
      room:useCard(use)
    else
      room:loseHp(player, 1, self.name)
    end
  end,
}

local yixintongti = fk.CreateTriggerSkill{
  name = "yixintongti",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash" and U.hasFullRealCard(player.room, data.card) then
      local room = player.room
      local from = room:getPlayerById(data.from)
      local targets = table.filter(room.alive_players, function (p)
        return p ~= player and p.id ~= data.from and from:canUseTo(data.card, p, {bypass_distances = false, bypass_times = true})
      end)
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local _data = {self.name, "#yixintongti-invoke:::"..data.card:toLogString()}
    local to = room:doRaceRequest("AskForSkillInvoke", self.cost_data, json.encode(_data))
    if to then
      room:moveCardTo(data.card, Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true)
      room:doIndicate(player.id, { to.id })
      AimGroup:cancelTarget(data, player.id)
      AimGroup:addTargets(room, data, to.id)
    end
  end,
}

chengong:addSkill(yishengxuanming)
chengong:addSkill(yixintongti)

Fk:loadTranslationTable{
  ["ev__chengong"] = "音音音",
  ["designer:ev__chengong"] = "轮回中听琴",
  ["yishengxuanming"] = "一生悬命",
  [":yishengxuanming"] = "锁定技，准备阶段，你令一名角色摸两张牌，然后其选择一项：1.使用【杀】；2.令你失去1点体力。",
  ["#yishengxuanming-slash"] = "请使用【杀】，否则%src失去1点体力",
  ["#yishengxuanming-choose"] = "一生悬命：请选择一名角色",
  ["yixintongti"] = "一心同体",
  [":yixintongti"] = "当你成为【杀】的目标时，你可令是此【杀】合法目标的所有其他角色各选择是否获得此【杀】；若其选择是，其将此【杀】转移给其。",
  ["#yixintongti-invoke"] = "你可以获得%arg并成为之目标",
}

local bianhua = General(extension, "ev__bianhua", "ev", 4, 4, General.Female)

local ev__xuezhihuahai = fk.CreateTriggerSkill{
  name = "ev__xuezhihuahai",
  anim_type = "defensive",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  derived_piles = {"flower"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash" and #player:getPile("flower") < player.hp
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 2, true, self.name, true, ".", "#ev__xuezhihuahai")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("flower", self.cost_data, true, self.name)
    local cards = {}
    if not room:getPlayerById(data.from).dead then
      cards = room:askForDiscard(room:getPlayerById(data.from), 1, 999, true, self.name, true, ".|.|heart,diamond",
      "#huahai-throw:::"..#player:getPile("flower")..":"..data.card:toLogString())
      if #cards < #player:getPile("flower") then
        data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
      end
    end
  end,
}

local ev__chituanhua = fk.CreateTriggerSkill{
  name = "ev__chituanhua",
  anim_type = "offensive",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|flower|.|.", "#ev__chituanhua-invoke", "flower")
    if #card > 0 then
      room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
    else
      room:loseHp(player, 1, self.name)
    end
    local n = math.max(player:getLostHp(), 1)
    if #room:askForDiscard(target, n, n, true, self.name, true, ".|.|spade,club", "#chituanhua-throw:::"..n) == 0 then
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

bianhua:addSkill(ev__xuezhihuahai)
bianhua:addSkill(ev__chituanhua)

Fk:loadTranslationTable{
  ["ev__bianhua"] = "彼岸花",
  ["designer:ev__bianhua"] = "次氯酸",
  ["ev__xuezhihuahai"] = "血之花海",
  ["#ev__xuezhihuahai"] = "血之花海：你可将一至两张牌置于角色牌上",
  ["flower"] = "花海",
  [":ev__xuezhihuahai"] = "当你指定或成为【杀】的目标后，若“花海”数小于你的体力值，你可将一至两张牌置于角色牌上，称为“花海”；然后你可令此【杀】的使用者弃置任意张红色牌，若其弃置的牌数小于“花海”数，此【杀】无效。",
  ["#huahai-throw"] = "请弃置任意红色牌，若少于%arg张则%arg2无效",
  ["ev__chituanhua"] = "赤团华",
  [":ev__chituanhua"] = "回合技（始），你可失去1点体力或将一张“花海”置入弃牌堆，令其选择一项：1.弃置X张黑色牌；2.受到你造成的1点伤害（X为你已损失的体力值且至少为1）。",
  ["#ev__chituanhua-invoke"] = "请选择一张“花海”置入弃牌堆，不选则失去1点体力",
  ["#chituanhua-throw"] = "请弃置%arg张黑色牌，否则受到1点伤害",
}

local Fujino = General(extension, "ev__fujino", "ev", 3, 3, General.Female)

local ev__waiqumoyan = fk.CreateTriggerSkill{
  name = "ev__waiqumoyan",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    --local victim = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self.name) and player.id ~= data.to--没人会对自己发动吧？
  end,
  on_cost = function(self, event, target, player, data)
    --local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#ev__waiqumoyan::"..data.to)
    local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, tostring(Exppattern{ id = unshown }), "#ev__waiqumoyan::"..data.to)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    player:showCards({self.cost_data})
    local color = Fk:getCardById(self.cost_data):getColorString()
    room:addPlayerMark(to, "@!waiqu_"..color.."-turn")
    if to:getMark("@!waiqu_red-turn") > 0 and to:getMark("@!waiqu_black-turn") > 0 then
      room:setPlayerMark(to, "@!waiqu_red-turn", 0)
      room:setPlayerMark(to, "@!waiqu_black-turn", 0)
      room:damage({
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local ev__tongjue = fk.CreateTriggerSkill{
  name = "ev__tongjue",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.Damaged},
  derived_piles = {"$pain"},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Start
    else
      return target == player and player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = player:drawCards(1, self.name)
    player.room:delay(100)
    player.room:moveCardTo(card, Card.PlayerSpecial, player, fk.ReasonJustMove, self.name, "$pain", false)
    if #player:getPile("$pain") >= player.maxHp then
      player.room:moveCardTo(player:getPile("$pain"), Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", false)
    end
  end,
}

Fujino:addSkill(ev__waiqumoyan)
Fujino:addSkill(ev__tongjue)

Fk:loadTranslationTable{
  ["ev__fujino"] = "浅上藤乃",
  ["designer:ev__fujino"] = "KINGDOM43",
  ["ev__waiqumoyan"] = "歪曲魔眼",
  ["#ev__waiqumoyan"] = "歪曲魔眼：你可展示一张手牌令%dest获得一个相同颜色的“歪曲”标记",
  [":ev__waiqumoyan"] = "当你使用牌指定一个目标后，你可展示一张手牌，令其获得一个相同颜色的“歪曲”标记；然后若其有两种颜色的“歪曲”标记，你对其造成1点伤害，其弃所有“歪曲”标记。当前回合结束时，其弃所有“歪曲”标记。",
  ["ev__tongjue"] = "痛觉残留",
  [":ev__tongjue"] = "锁定技，准备阶段或你受到伤害后，你摸一张牌并将之扣置于角色牌上，称为“痛”；然后若“痛”数不小于你的体力上限，你获得所有“痛”。",
  ["$pain"] = "痛",
}
local qingxingdeng = General(extension, "ev__qingxingdeng", "ev", 3, 3, General.Female)

local ev__mingdeng = fk.CreateTriggerSkill{
  name = "ev__mingdeng",
  anim_type = "support",
  events = {fk.TurnStart, fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TurnStart then
        return EV.isFriend(player, target)
      else
        for _, move in ipairs(data) do
          if move.from and player.room:getPlayerById(move.from):getMark("@ev__mingdeng-turn") ~= 0 and move.moveReason == fk.ReasonDiscard then-- and move.proposer == player.id
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                if player.room:getPlayerById(move.from):getMark("ev__mingdeng-turn") == 0 then
                  player.room:addPlayerMark(player.room:getPlayerById(move.from),"ev__mingdeng-turn")
                  return true
                end
              end
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local ids = {}
      for _, move in ipairs(data) do
        if player.room:getPlayerById(move.from):getMark("@ev__mingdeng-turn") ~= 0 and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insert(ids, info.cardId)
            end
          end
        end
        local friend = player.room:getPlayerById(move.from)
        local suit = friend:getMark("@ev__mingdeng-turn")
        ids = table.filter(ids, function (id) return Fk:getCardById(id):getSuitString(true) == suit end)
        if #ids > 0 then
        local cards = player.room:askForCard(friend, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#ev__mingdeng-show")
          if #cards > 0 then
            self.cost_data = cards
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".",
      }
      room:judge(judge)
      room:setPlayerMark(target, "@ev__mingdeng-turn", judge.card:getSuitString(true))
    else
      local ids = {}
      for _, move in ipairs(data) do
        if room:getPlayerById(move.from):getMark("@ev__mingdeng-turn") ~= 0 and move.moveReason == fk.ReasonDiscard then
          local new_info = {}
          for _, info in ipairs(move.moveInfo) do
            if table.contains(self.cost_data, info.cardId) and Fk:getCardById(info.cardId):getMark("@@shown-inhand") == 0 then
              table.insertIfNeed(ids, info.cardId)
            else
              table.insert(new_info, info)
            end
            if #ids > 0 then
              move.moveInfo = new_info
            end
          end
        end
        EV.OpenCards(room, room:getPlayerById(move.from), self.cost_data, self.name)
      end
      room:sendLog{
        type = "#cancelDismantle",
        card = ids,
        arg = self.name,
      }
    end
  end,
}

local ev__xihundeng = fk.CreateActiveSkill{
  name = "ev__xihundeng",
  anim_type = "offensive",
  min_card_num = 1,
  min_target_num = 1,
  prompt = "#ev__xihundeng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    else
      return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
      and table.every(selected, function (id) return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit end)
    end
  end,
  target_filter = function (self, to_select, selected, _, _, _, player)
    if #selected == 0 then
      return to_select ~= player.id
    else
      return table.every(selected, function (id)
      return Fk:currentRoom():getPlayerById(to_select):getHandcardNum() ~= Fk:currentRoom():getPlayerById(id):getHandcardNum() end)
      and to_select ~= player.id
    end
  end,
  feasible = function(self, selected, selected_cards)
    return #selected == #selected_cards
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local suits = {"heart","spade","diamond","club"}
    for _, id in ipairs(effect.cards) do
      local suit = Fk:getCardById(id):getSuitString()
      table.removeOne(suits, suit)
    end
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    for _, p in ipairs(effect.tos) do
      p = room:getPlayerById(p)
      local invoke = false
      if #suits > 0 then
        local cards = player.room:askForDiscard(p, 1, 1, false, self.name, true,  ".|.|" .. table.concat(suits, ",") , "#ev__xihundeng-give::"..player.id)
        if #cards > 0 then
          invoke = true
          room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, self.name, "", true, player.id)
        end
      end
      if not invoke then
        room:damage({
          from = player,
          to = p,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name
        })
      end
    end
  end,
}

qingxingdeng:addSkill(ev__mingdeng)
qingxingdeng:addSkill(ev__xihundeng)

Fk:loadTranslationTable{
  ["ev__qingxingdeng"] = "青行灯",
  ["designer:ev__qingxingdeng"] = "次氯酸",
  ["ev__mingdeng"] = "明灯",
  ["@ev__mingdeng-turn"] = "明灯",
  [":ev__mingdeng"] = "回合技（始），若其为己方角色，你可判定，则其于当前回合内首次因弃置而失去牌前，其可明置其中与结果花色相同的一张牌，取消此牌的此次移动。",
  ["#ev__mingdeng-show"] = "明灯：你可明置一张牌取消此次移动",
  ["ev__xihundeng"] = "吸魂灯",
  [":ev__xihundeng"] = "阶段技，你可弃置至少一张手牌（若不少于两张则花色须均不同），令等量名（若不少于两名则手牌数须均不同）角色各选择一项：1.将一张与你以此法弃置的牌花色均不同的手牌交给你；2.受到你造成的1点伤害。",
  ["#ev__xihundeng"] = "你可弃置至少一张手牌并选择等量角色",
  ["#ev__xihundeng-give"] = "明灯：请将一张牌交给%dest",
}

local Ruby = General(extension, "ev__ruby", "ev", 4, 4, General.Female)

--[[local xinyuemeigui = fk.CreateViewAsSkill{
  name = "xinyuemeigui",
  pattern = "slash",
  card_filter = Util.FalseFunc,
  view_as = function(self)
    local card = Fk:cloneCard("ev__slash")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 and Fk:getCardById(id).color == Card.Red end)
    if #cards > 0 then
      EV.OpenCards(room, player, cards, self.name)
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    and table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 and Fk:getCardById(id).color == Card.Red end)
  end,
  enabled_at_response = Util.FalseFunc,
}]]

local xinyuemeigui = fk.CreateActiveSkill{
  name = "xinyuemeigui",
  anim_type = "offensive",
  prompt = "你可明置所有红色手牌，视为使用【杀】",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@shown-inhand") == 0 and Fk:getCardById(id).color == Card.Red end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@shown-inhand") == 0 and Fk:getCardById(id).color == Card.Red end)
    if #cards > 0 then
      EV.OpenCards(room, player, cards, self.name)
    end
    U.askForUseVirtualCard(room, player, "ev__slash", nil, self.name, nil, true)
  end,
}

local xinyuemeigui_trigger = fk.CreateTriggerSkill{
  name = "#xinyuemeigui_trigger",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and #TargetGroup:getRealTargets(data.tos) == 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(TargetGroup:getRealTargets(data.tos)[1])
    local targets = table.map(EV.getShortRoute(player, to), Util.IdMapper)
    table.removeOne(targets, to.id)
    if #targets > 0 then
      local use = room:askForUseCard(player, "slash", "slash", "#xinyuemeigui-use", true, {include_targets = targets, bypass_times = true})
      if use then
        use.extraUse = true
        self.cost_data = use
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:useCard(self.cost_data)
  end,
}

local waixianglijisu = fk.CreateViewAsSkill{
  name = "waixianglijisu",
  pattern = "jink",
  card_filter = Util.FalseFunc,
  view_as = function(self)
    local card = Fk:cloneCard("ev__jink")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    if not player:isKongcheng() then
      EV.ConcealCards(room, player, player:getCardIds(Player.Hand), self.name)
    end
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    if not response then
      return table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).color == Card.Red end)
    end
  end,
}

local waixianglijisu_distance = fk.CreateDistanceSkill{
  name = "#waixianglijisu_distance",
  correct_func = function(self, from)
    if from:hasSkill(self) then
      return 0 - #from:getTableMark("@$shown")
    end
  end,
}

xinyuemeigui:addRelatedSkill(xinyuemeigui_trigger)
waixianglijisu:addRelatedSkill(waixianglijisu_distance)
Ruby:addSkill(xinyuemeigui)
Ruby:addSkill(waixianglijisu)

Fk:loadTranslationTable{
  ["ev__ruby"] = "露比罗丝",
  ["designer:ev__ruby"] = "时雨不迟",
  ["xinyuemeigui"] = "新月玫瑰",
  ["#xinyuemeigui_trigger"] = "新月玫瑰",
  [":xinyuemeigui"] = "阶段技，你可明置所有红色手牌，视为使用【杀】。当你使用的【杀】结算结束后，若此【杀】目标唯一，你可对你到其的短路径上除其外的一名角色使用【杀】。",
  ["#xinyuemeigui-use"] = "新月玫瑰：你可使用【杀】",
  ["waixianglijisu"] = "外向力急速",
  [":waixianglijisu"] = "你与其他角色的距离-X（X为你的明置手牌数）。当你需要使用【闪】时，若你的手牌均为红色且均已明置，你可暗置所有手牌，视为使用【闪】。",
}

local Mizuhashi = General(extension, "ev__mizuhashi", "ev", 3, 3, General.Female)

local ev__jiyuan = fk.CreateTriggerSkill{
  name = "ev__jiyuan",
  --anim_type = "drawcard",
  events = {fk.EventPhaseStart, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return target == player and player.phase == Player.Start
      elseif player.phase == Player.NotActive then
        for _, move in ipairs(data) do
          return move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from
          and move.skillName == "ev__duxin"
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local room = player.room
      local targets = table.map(table.filter(room:getOtherPlayers(player), function (to)
        return table.every(room:getOtherPlayers(player), function (p) return p:getHandcardNum() >= to:getHandcardNum() end)
      end), Util.IdMapper)
      local to = room:askForChoosePlayers(player, targets, 1, 1, "#ev__jiyuan", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local to = room:getPlayerById(self.cost_data)
      if not player:hasSkill("ev__duxin") then
        room:handleAddLoseSkills(player, "ev__duxin")
      end
      if not to:hasSkill("ev__duxin") then
        room:handleAddLoseSkills(to, "ev__duxin")
      end
    else
      local ids = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from
        and move.skillName == "ev__duxin" then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
            room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(ids, info.cardId)
            end
          end
        end
      end
      if #ids > 0 then
        room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
      end
    end
  end,
}

local ev__duxin = fk.CreateTriggerSkill{
  name = "ev__duxin",
  anim_type = "offensive",
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room:getOtherPlayers(player), function(p)
      return player:getHandcardNum() < p:getHandcardNum() end), Util.IdMapper)
      if #targets > 0 then
        local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#ev__duxin-choose", self.name, false)
        if #to > 0 then
          self.cost_data = to[1]
          return true
        end
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local cid = room:askForCardChosen(player, to, "h", self.name)
    if cid then
      room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    end
    if to:getHandcardNum() <= player:getHandcardNum() then
      room:handleAddLoseSkills(player, "-ev__duxin")
    end
  end,
}

local ev__duxin_maxcards = fk.CreateMaxCardsSkill{
  name = "#ev__duxin_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(self) then
      return -1
    end
  end,
}

ev__duxin:addRelatedSkill(ev__duxin_maxcards)
Mizuhashi:addSkill(ev__jiyuan)
Mizuhashi:addSkill(ev__duxin)

Fk:loadTranslationTable{
  ["ev__mizuhashi"] = "水桥帕露西",
  ["designer:ev__mizuhashi"] = "KINGDOM43",
  ["illustrator:ev__mizuhashi"] = "東天紅",
  ["ev__jiyuan"] = "积怨",
  [":ev__jiyuan"] = "准备阶段，你可令你与除你外手牌数最小的一名角色获得“妒心”；你的回合外，当一名角色因“妒心”弃置而失去牌后，你获得之。",
  ["#ev__jiyuan"] = "你可令你与除你外手牌数最小的一名角色获得“妒心”",
  ["ev__duxin"] = "妒心",
  ["#ev__duxin-choose"] = "妒心：请选择手牌数大于你的一名角色",
  [":ev__duxin"] = "锁定技，你的手牌上限-1。结束阶段，你弃置手牌数大于你的一名角色的一张手牌；然后若其手牌数不大于你，你失去此技能。",
}

local Homura = General(extension, "ev__homura", "ev", 3, 3, General.Female)

local yuanpanshouhu = fk.CreateTriggerSkill{
  name = "yuanpanshouhu",
  anim_type = "drawcard",
  derived_piles = {"$yuanpan"},
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local gets = {}
    for _, move in ipairs(data) do      
      for _, info in ipairs(move.moveInfo) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          table.insertIfNeed(gets, info.cardId)
        end
      end
      local cards = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = gets }), "#yuanpanshouhu")
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerSpecial, player, fk.ReasonJustMove, self.name, "$yuanpan", false)
      end
      if #player:getPile("$yuanpan") > 0 then
        local card = room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|$yuanpan|.|.", "#yuanpanshouhu-get", "$yuanpan")
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
          room:addCardMark(Fk:getCardById(card[1]), "@@yuanpanshouhu-turn")
        end
      end
    end
  end,
}

local yuanpanshouhu_tar = fk.CreateTargetModSkill{
  name = "#yuanpanshouhu_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self) and card and card:getMark("@@yuanpanshouhu-turn") > 0 then
      return 999
    end
  end,
}

local shikongcaozuo = fk.CreateTriggerSkill{
  name = "shikongcaozuo",
  anim_type = "drawcard",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 then
      return event == fk.TargetSpecified or (player:getMark("@shikongcaozuo") > 0 and player.id ~= data.from)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return #player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#shikongcaozuo-throw::"..data.to) > 0
    else
      return #player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#shikongcaozuo-discard:::"..player:getMark("@shikongcaozuo")) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      if not room:getPlayerById(data.to):isAllNude() then
        local id = room:askForCardChosen(player, room:getPlayerById(data.to), "hej", self.name)
        if id then
          room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, player.id)
        end
      end
    else
      local n = player:getMark("@shikongcaozuo") - player:getHandcardNum()
      if n > 0 then
        player:drawCards(n, self.name)
      end
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@shikongcaozuo", player:getHandcardNum())
  end,
}

yuanpanshouhu:addRelatedSkill(yuanpanshouhu_tar)
Homura:addSkill(yuanpanshouhu)
Homura:addSkill(shikongcaozuo)

Fk:loadTranslationTable{
  ["ev__homura"] = "晓美焰",
  ["designer:ev__homura"] = "陆丿伯言",
  ["yuanpanshouhu"] = "圆盘守护",
  ["@@yuanpanshouhu-turn"] = "圆盘守护",
  ["#yuanpanshouhu"] = "你可将其中一张牌扣置于角色牌上",
  ["#yuanpanshouhu-get"] = "你可获得角色牌上的一张牌",
  [":yuanpanshouhu"] = "当你不以此法获得牌时，你可将其中至多一张牌扣置于角色牌上，然后你可获得角色牌上的一张牌，你于当前回合内使用此牌无次数限制。",
  ["shikongcaozuo"] = "时空操作",
  ["@shikongcaozuo"] = "时空操作",
  [":shikongcaozuo"] = "回合技，当你使用牌指定一个目标后/成为其他角色使用牌的目标后，你可弃置一张牌，然后获得其区域里的一张牌/将手牌补至与你的上回合结束时相同。",
  ["$yuanpan"] = "圆盘",
  ["#shikongcaozuo-throw"] = "时空操作：你可弃置一张牌，获得%dest区域里的一张牌",
  ["#shikongcaozuo-discard"] = "时空操作：你可弃置一张牌，将手牌补至%arg张",
}


local Alter = General(extension, "ev__alter", "ev", 4, 4, General.Female)

local ev__qishi = fk.CreateTriggerSkill{
  name = "ev__qishi",
  anim_type = "drawcard",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (event == fk.TargetConfirmed or data.firstTarget)
    and player:usedSkillTimes(self.name) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #table.map(table.filter(room.alive_players, function(p) return p.role == "lord" or p.role == "loyalist" end), Util.IdMapper)
    if n == 1 then
      player:drawCards(1, self.name)
    elseif n > 0 then
      local ids = room:getNCards(n)
      local cids = U.askForExchange(player, self.name, player.general, ids, player:getCardIds("he"), "#ev__qishi-exchange", 1, true)
      if #cids > 0 then
        local handcards = table.filter(cids, function (id)
          return table.contains(player:getCardIds("he"), id)
        end)
        local cards = table.filter(cids, function (id)
          return table.contains(room.draw_pile, id)
        end)
        U.swapCardsWithPile(player, handcards, cards, self.name, "Top", true, player.id)
      end
    end
  end,
}

local ev__wuzhu = fk.CreateActiveSkill{
  name = "ev__wuzhu",
  prompt = "#ev__wuzhu",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng()
  end,
  target_num = 0,
  min_card_num = 1,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).color == Card.Red and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    and Fk:getCardById(to_select):getMark("@@shown-inhand") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    EV.OpenCards(room, player, effect.cards, self.name)
    room:addPlayerMark(player, "@@ev__wuzhu")
  end
}

local wuzhu_prohibit = fk.CreateProhibitSkill{
  name = "#ev__wuzhu_prohibit",
  prohibit_use = function(self, player, card)
    if player:hasSkill("ev__wuzhu") and player:getMark("@@ev__wuzhu") ~= 0 then
      return card.trueName == "slash"
    end
  end,
}

local wuzhu_trigger = fk.CreateTriggerSkill{
  name = "#ev__wuzhu_trigger",
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and EV.isFriend(player, target) and player:getMark("@@ev__wuzhu") ~= 0 then
      return table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).color == Card.Red end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).color == Card.Red end)
    if #cards > 0 then
      local id = player.room:askForCard(player, 1, 1, false, self.name, false, tostring(Exppattern{ id = cards }), "#ev__wuzhu-discard")
      if #id > 0 then
        self.cost_data = id[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    EV.ConcealCards(player.room, player, self.cost_data, self.name)
    return true
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("ev__wuzhu") and player:getMark("@@ev__wuzhu") ~= 0
    and #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@ev__wuzhu", 0)
  end
}

ev__wuzhu:addRelatedSkill(wuzhu_trigger)
ev__wuzhu:addRelatedSkill(wuzhu_prohibit)
Alter:addSkill(ev__qishi)
Alter:addSkill(ev__wuzhu)

Fk:loadTranslationTable{
  ["ev__alter"] = "贞德",
  ["designer:ev__alter"] = "小樱",
  ["ev__qishi"] = "启示",
  [":ev__qishi"] = "回合技，当你指定或成为牌的目标后，你可观看牌堆顶的X张牌，然后若X不为/为1，则你可用一张牌交换其中的一张牌/摸一张牌（X为“神谕”阵营角色数）。",
  ["#ev__qishi-exchange"] = "启示：你可用一张牌交换其中的一张牌",
  ["ev__wuzhu"] = "吾主在此",
  ["@@ev__wuzhu"] = "<font color=\"#EC5800\">吾主在此</font>",
  [":ev__wuzhu"] = "限定技，出牌阶段，你可明置至少一张红色手牌，获得以下效果：你不能使用【杀】；当己方角色受到伤害时，你暗置一张红色手牌，防止此伤害；回合开始时，若你没有明置手牌，此效果失效。",
  ["#ev__wuzhu"] = "你可明置至少一张红色手牌",
  ["#ev__wuzhu_prohibit"] = "吾主",
  ["#ev__wuzhu-discard"] = "请暗置一张红色手牌，防止此伤害",
}

local Ereshkigal = General(extension, "ev__ereshkigal", "ev", 3, 3, General.Female)

local mingfuyouhu = fk.CreateTriggerSkill{
  name = "mingfuyouhu",
  anim_type = "support",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 and data.from ~= data.to then
      return player:getMark("@@mingjiequanneng") > 0 or target:isKongcheng() or table.every(target:getCardIds("h"), function (id)
        return Fk:getCardById(id).color == Card.Black
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if target:isKongcheng() or player:getMark("@@mingjiequanneng") > 0 then
      return player.room:askForSkillInvoke(player, self.name, nil, "#mingfuyouhu-invoke::"..target.id)
    else
      return player.room:askForSkillInvoke(target, self.name, nil, "#mingfuyouhu-throw")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target:isKongcheng() or player:getMark("@@mingjiequanneng") > 0 then
      target:drawCards(2, self.name)
      if player:getMark("@@mingjiequanneng") > 0
      and room:askForSkillInvoke(player, self.name, nil, "#mingfuyouhu_ex::"..target.id..":"..data.card:toLogString()) then
        EV.nullifiedCard(data, data.card, target)
      end
    else
      target:throwAllCards("h")
      if room:askForSkillInvoke(player, self.name, nil, "#mingfuyouhu_ex::"..target.id..":"..data.card:toLogString()) then
        EV.nullifiedCard(data, data.card, target)
      end
    end
  end,
}

local mingjiequanneng = fk.CreateActiveSkill{
  name = "mingjiequanneng",
  prompt = "你可将弃牌堆里的X张牌洗为新牌堆",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:getMark("mingjiequanneng-invoke") > 0
  end,
  target_num = 0,
  card_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setPlayerMark(player, "mingjiequanneng-invoke", 0)
    local deaths = #table.filter(room.players, function (p) return p.dead end)
    local black = 0
    for _, p in ipairs(room.alive_players) do
      for _, id in ipairs(p:getCardIds("ej")) do
        if Fk:getCardById(id).color == Card.Black then
          black = black + 1
        end
      end
    end
    local x = deaths * black
    if x > 0 then
      local cards = room:askForCardsChosen(player, player, x, x, {
        card_data = {
          { "pile_discard", room.discard_pile }
        }
      }, self.name, "#mingjiequanneng-choose:::" .. x)
      table.forEach(cards, function(id) table.removeOne(room.discard_pile, id) end)
      EV.CreateDrawpile(room, cards, Card.DiscardPile)
      room:addPlayerMark(player, "@@mingjiequanneng")
    end
  end
}

local mingjiequanneng_trigger = fk.CreateTriggerSkill{
  name = "#mingjiequanneng_trigger",
  mute = true,

  refresh_events = {fk.TurnStart, fk.StartPlayCard},
  can_refresh = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TurnStart then
        return player:getMark("@@mingjiequanneng") > 0
      else
        return #player.room.discard_pile > #player.room.draw_pile
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:setPlayerMark(player, "@@mingjiequanneng", 0)
    else
      player.room:setPlayerMark(player, "mingjiequanneng-invoke", 1)
    end
  end
}

mingjiequanneng:addRelatedSkill(mingjiequanneng_trigger)
Ereshkigal:addSkill(mingfuyouhu)
Ereshkigal:addSkill(mingjiequanneng)

Fk:loadTranslationTable{
  ["ev__ereshkigal"] = "艾蕾什基伽尔",
  ["designer:ev__ereshkigal"] = "KINGDOM43",
  ["mingfuyouhu"] = "冥府佑护",
  [":mingfuyouhu"] = "回合技，当一名角色成为另一名角色使用牌的目标后，<font color=\"#D2042D\">{若其：没有手牌，}</font>你可令其摸两张牌；<font color=\"#D2042D\">{手牌均为黑色牌，其可弃置所有手牌，}</font>然后你可令此牌对其无效。",
  ["#mingfuyouhu-invoke"] = "你可以对%dest发动“冥府佑护”",
  ["#mingfuyouhu-throw"] = "冥府佑护：你可以弃置所有手牌",
  ["#mingfuyouhu_ex"] = "你可令%arg对%dest无效",
  ["mingjiequanneng"] = "冥界权能",
  [":mingjiequanneng"] = "出牌阶段，若弃牌堆里的牌多于牌堆，你可将弃牌堆里的X张牌洗为新牌堆，将原牌堆洗入弃牌堆，然后你删除<font color=\"#D2042D\">{ }</font>里的描述直至你的下回合开始（X为场上的黑色牌数与死亡人数之积）。",
  ["#mingjiequanneng-choose"] = "请选择弃牌堆的%arg张牌",
  ["@@mingjiequanneng"] = "冥界权能",
}

local Tomoe = General(extension, "ev__tomoe", "ev", 4, 4, General.Female)

local jinsejiban = fk.CreateTriggerSkill{
  name = "jinsejiban",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and target.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #player:getCardIds("he") >= 2 and room:askForSkillInvoke(player, self.name, nil, "#jinsejiban-invoke") then
      local result = room:askForYiji(player, player:getCardIds("he"), room:getOtherPlayers(player), self.name, 2, 2)
      for p, _ in pairs(result) do
        local to = room:getPlayerById(p)
        if #result[p] > 0 and player:getHandcardNum() == to:getHandcardNum() then
          player:drawCards(1, self.name)
          break
        end
      end
    else
      room:addPlayerMark(player, "jinsejiban-turn")
    end
  end,
}

local jinsejiban_maxcards = fk.CreateMaxCardsSkill{
  name = "#jinsejiban_maxcards",
  fixed_func = function(self, player)
    if player:hasSkill(self) and player:getMark("jinsejiban-turn") > 0 then
      return player.maxHp
    end
  end
}

local duandaiqianghuo = fk.CreateViewAsSkill{
  name = "duandaiqianghuo",
  anim_type = "offensive",
  pattern = "slash",
  prompt = '你可重铸【杀】或武器牌，视为使用【杀】（无距离限制）',
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash" or Fk:getCardById(to_select).sub_type == Card.SubtypeWeapon
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("slash")
    card:setMark(self.name, cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local put = use.card:getMark(self.name)
    if put ~= 0 and table.contains(player:getCardIds("he"), put) then
      room:recastCard(put, player, self.name)
    end
    room:setCardMark(use.card, self.name, 0)
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
}

local duandaiqianghuo_trigger = fk.CreateTriggerSkill{
  name = "#duandaiqianghuo_trigger",
  events = {fk.CardUsing},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|trick", "#duandaiqianghuo-discard:::"..data.card:toLogString())
    return #card > 0
  end,
  on_use = function(self, event, target, player, data)
    player:addCardUseHistory(data.card.trueName, -1)
  end,
}

local duandaiqianghuo_targetmod = fk.CreateTargetModSkill{
  name = "#duandaiqianghuo_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, "duandaiqianghuo")
  end,
}

jinsejiban:addRelatedSkill(jinsejiban_maxcards)
duandaiqianghuo:addRelatedSkill(duandaiqianghuo_trigger)
duandaiqianghuo:addRelatedSkill(duandaiqianghuo_targetmod)
Tomoe:addSkill(jinsejiban)
Tomoe:addSkill(duandaiqianghuo)

Fk:loadTranslationTable{
  ["ev__tomoe"] = "巴麻美",
  ["designer:ev__tomoe"] = "陆丿伯言",
  ["jinsejiban"] = "金色羁绊",
  [":jinsejiban"] = "出牌阶段开始时，你可选择一项：1.将两张牌交给一至两名其他角色，然后若其中有与你手牌数相同的角色，你摸一张牌；2.令你的手牌上限于本回合内等于体力上限。",
  ["#jinsejiban-invoke"] = "你可以将两张牌交给其他角色，若选取消则改变手牌上限",
  ["duandaiqianghuo"] = "缎带枪火",
  ["#duandaiqianghuo-discard"] = "你可弃置一张魔法牌令%arg不计入次数限制",
  [":duandaiqianghuo"] = "当你需要使用【杀】时，你可重铸【杀】或武器牌，视为使用【杀】（无距离限制）。当你使用牌时，你可弃置一张魔法牌，令此牌不计入次数限制。",
}

local Brigitte = General(extension, "ev__brigitte", "ev", 4, 4, General.Female)

local nengliangdunji = fk.CreateActiveSkill{
  name = "nengliangdunji",
  anim_type = "control",
  prompt = "你可将一张【杀】置为护盾",
  target_num = 0,
  card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).trueName == "slash"
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:addToPile("shield", effect.cards, true, self.name)
    local targets = table.map(table.filter(player.room.alive_players, function(p) 
      return player:inMyAttackRange(p) end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#nengliangdunji-choose", self.name, true)
    if #tos > 0 then
      room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true, player.id)
      local to = room:getPlayerById(tos[1])
      local number = Fk:getCardById(effect.cards[1]).number
      local cards = table.filter(to:getCardIds("h"), function (id)
        return Fk:getCardById(id).number > number and Fk:getCardById(id).trueName == "jink"
      end)
      local card = room:askForCard(to, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), "#nengliangdunji")
      if #card > 0 then
        room:responseCard({
          from = to.id,
          card = Fk:getCardById(card[1]),
          responseToEvent = effect,
        })
      else
        room:addPlayerMark(to, "@@nengliangdunji")
      end
    end
  end,

  refresh_events = {fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true, true) and target and target:getMark("@@nengliangdunji") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:addPlayerMark(target, "nengliangdunji-turn")
    elseif event == fk.TurnEnd then
      if target:getMark("nengliangdunji-turn") > 0 then
        player.room:setPlayerMark(target, "@@nengliangdunji", 0)
      end
    end
  end,
}

local nengliangdunji_prohibit = fk.CreateProhibitSkill{
  name = "#nengliangdunji_prohibit",
  is_prohibited = function(self, from, to, card)
    return from:getMark("@@nengliangdunji") > 0 and card.color == Card.Black and from ~= to
  end,
}

local huifubao = fk.CreateTriggerSkill{
  name = "huifubao",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room.alive_players, function (p)
      return #p:getTableMark("@$shown") == 0 end), Util.IdMapper)
    if #targets > 0 then
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#huifubao-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = tos[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local cards = to:drawCards(1, self.name)
    EV.OpenCards(room, to, cards, self.name)
    if Fk:getCardById(cards[1]).suit == Card.Heart then
      room:addCardMark(Fk:getCardById(cards[1]), "huifubao-inhand")
      room:handleAddLoseSkills(to, "huifubao&")
    end
  end,
}

local huifubao_get = fk.CreateViewAsSkill{
  name = "huifubao&",
  anim_type = "offensive",
  pattern = "peach",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select):getMark("huifubao-inhand") > 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("ev__peach")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}

Fk:addSkill(huifubao_get)
nengliangdunji:addRelatedSkill(nengliangdunji_prohibit)
Brigitte:addSkill(nengliangdunji)
Brigitte:addSkill(huifubao)

Fk:loadTranslationTable{
  ["ev__brigitte"] = "布丽吉塔",
  ["designer:ev__brigitte"] = "陆丿伯言",
  ["nengliangdunji"] = "能量盾击",
  [":nengliangdunji"] = "阶段技，你可将一张【杀】置为护盾，然后你可将此护盾置入弃牌堆，令你攻击范围内的一名角色选择一项：1.打出一张点数大于此护盾的【闪】；2.令除其外的角色不是其使用黑色牌的合法目标，直至其下回合结束。",
  ["#nengliangdunji-choose"] = "你可将此护盾置入弃牌堆并选择一名攻击范围内的角色",
  ["#nengliangdunji"] = "请打出一张【闪】",
  ["@@nengliangdunji"] = "能量盾击",
  ["#nengliangdunji_prohibit"] = "能量盾击",
  ["huifubao"] = "恢复包",
  ["huifubao&"] = "恢复包",
  [":huifubao"] = "结束阶段，你可令一名没有明置手牌的角色摸一张牌并明置此牌，然后若此牌为红桃牌，其可将此牌当【茶】使用。",
  ["#huifubao-choose"] = "你可令一名没有明置手牌的角色摸一张牌",
}

local lappland = General(extension, "ev__lappland", "ev", 4, 4, General.Female)

local mental_distroy = fk.CreateTriggerSkill{
  name = "mental_distroy",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    --local victim = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self.name) and player.id ~= data.to--没人会对自己发动吧？
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#mental_distroy::"..data.to) then
      self.cost_data = data.to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
    if player:getHandcardNum() >= to:getHandcardNum() then
      room:setPlayerMark(to, "@@mental_distroy-turn", 1)
    end
  end,
}

local mental_distroy_effect = fk.CreateProhibitSkill{
  name = "#mental_distroy_effect",
  prohibit_use = function(self, player, card)
    return player:getMark("@@mental_distroy-turn") > 0 and card.trueName == "jink"
  end,
}

local ev__langhun = fk.CreateTriggerSkill{
  name = "ev__langhun",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("@ev__langhun") >= 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,

  refresh_events = {fk.DamageFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.from and data.from == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player,"@ev__langhun", data.damage)
    if player:getMark("@ev__langhun") >= 6 then
      player.room:setPlayerMark(player, "@ev__langhun", 0)
    end
  end,
}

local langhun_attackrange = fk.CreateAttackRangeSkill{
  name = "#ev__langhun_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("ev__langhun") then
      return 2
    end
  end,
}

local langhun_targetmod = fk.CreateTargetModSkill{
  name = "#ev__langhun_targetmod",
  extra_target_func = function(self, player, skill, card)
    if skill.trueName == "slash_skill" and card.trueName == "slash" and player:getMark("@ev__langhun") > 0 then
      return 1
    end
  end,
}

mental_distroy:addRelatedSkill(mental_distroy_effect)
ev__langhun:addRelatedSkill(langhun_attackrange)
ev__langhun:addRelatedSkill(langhun_targetmod)
lappland:addSkill(mental_distroy)
lappland:addSkill(ev__langhun)

Fk:loadTranslationTable{
    ["ev__lappland"] = "拉普兰德",
    ["designer:ev__lappland"] = "KINGDOM43",
    ["mental_distroy"] = "精神毁灭",
    ["#mental_distroy_effect"] = "精神毁灭",
    [":mental_distroy"] = "当你使用牌指定一个目标后，你可令其除锁定技与法则技外的技能于当前回合内失效；然后若其手牌数不大于你，其不能于当前回合内使用【闪】。",
    ["#mental_distroy"] = "你可令%dest的非锁定技于当前回合内失效",
    ["@@mental_distroy-turn"] = "精神毁灭",
    ["ev__langhun"] = "狼魂",
    [":ev__langhun"] = "锁定技，若你造成过的伤害数不小于：0，你的攻击范围+2；1，你使用的【杀】可额外选择一个目标；3，你造成的伤害+1；6，你重置计数为0。",
    ["@ev__langhun"] = "狼魂",

    ["$mental_distroy1"] = "让我见识见识你的能耐。",
    ["$mental_distroy2"] = "试着抵抗我吧！",
    ["~ev__lappland"] = "棒极了，这下，我践踏他们的欲望变得更强了！哈哈哈！",
  }


local Risotto = General(extension, "ev__risotto", "ev", 4)

local metalware = fk.CreateActiveSkill{
  name = "metalware",
  anim_type = "control",
  prompt = "你可令你攻击范围内的一名角色展示所有手牌",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
    and player:inMyAttackRange(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local unshown = table.filter(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    if #unshown > 0 then
      target:showCards(unshown)
      if room:askForSkillInvoke(target, self.name, nil, "#metalware-throw") then
        local cards = table.filter(unshown, function(id) return Fk:getCardById(id).color == Card.Black end)
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, false, target.id)
      end
    end
    if table.find(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).color == Card.Black end) then
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    else
      room:addPlayerMark(target, "@@metalware")
    end
  end,
}

local metalware_buff = fk.CreateTriggerSkill{
  name = "#metalware-buff",
  events = {fk.DrawNCards},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and target:getMark("@@metalware") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@@metalware", 0)
    data.n = data.n - 1
  end,
}

metalware:addRelatedSkill(metalware_buff)
Risotto:addSkill(metalware)

Fk:loadTranslationTable{
  ["ev__risotto"] = "里苏特",
  ["designer:ev__risotto"] = "豪曹",
  ["metalware"] = "金属制品",
  [":metalware"] = "阶段技，你可令你攻击范围内的一名角色展示所有手牌，其选择是否弃置其中的黑色牌，然后若其手牌中：没有黑色牌，其下个摸牌阶段少摸一张牌；有黑色牌，你对其造成1点伤害。",
  ["#metalware-throw"] = "你可以弃置手牌中的黑色牌",
  ["@@metalware"] = "金属制品",
}

local lingdong = General(extension, "ev__lingdong", "ev", 4, 4, General.Female)

local ev__wusasi = fk.CreateTriggerSkill{
  name = "ev__wusasi",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Discard and target.role_shown and
    (table.contains(player:getTableMark("wusasi_shown"), target.id) or table.contains(player:getTableMark("wusasi_slash"), target.id))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"ev__wusasi1", "ev__wusasi2"}
    local events = room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
      local deathStruct = e.data[1]
      return deathStruct.damage and deathStruct.damage.from and deathStruct.damage.from == target
    end, Player.HistoryTurn)
    if #events > 0 or (table.contains(player:getTableMark("wusasi_shown"), target.id) and table.contains(player:getTableMark("wusasi_slash"), target.id)) then
      target:drawCards(1, self.name)
      room:addPlayerMark(target, "AddMaxCards-turn")
    else
      local choice = room:askForChoice(target, choices, self.name)
      if choice == "ev__wusasi1" then
        target:drawCards(1, self.name)
      elseif choice == "ev__wusasi2" then
        room:addPlayerMark(target, "AddMaxCards-turn")
      end
    end
  end,

  refresh_events = {fk.CardUsing, "fk.RoleShown"},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      if player:hasSkill(self) and data.card.trueName == "slash" and target.role_shown then
        local slashs = room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
          return e.data[1].card.trueName == "slash" and e.data[1].from == target.id
        end, Player.HistoryGame)
        local events = room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
          return e.data[1].card.trueName == "slash" and EV.isFriend(target, room:getPlayerById(e.data[1].from)) and e.data[1].from ~= target.id
        end, Player.HistoryGame)
        return #slashs == 1 and #events == 0
      end
    else
      if player:hasSkill(self) and data.from == target.id then
        --return #table.filter(room:getOtherPlayers(target), function (p) return EV.isFriend(target, p) end) == 0
        local mark = player:getTableMark("wusasi_shown")
        return #table.filter(mark, function (p) return EV.isFriend(target, room:getPlayerById(p)) end) == 0
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      local mark = player:getTableMark("wusasi_slash")
      table.insertIfNeed(mark, target.id)
      room:setPlayerMark(player, "wusasi_slash", mark)
    else
      local mark = player:getTableMark("wusasi_shown")
      table.insertIfNeed(mark, target.id)
      room:setPlayerMark(player, "wusasi_shown", mark)
    end
  end
}

lingdong:addSkill(ev__wusasi)

Fk:loadTranslationTable{
  ["ev__lingdong"] = "凛冬",
  ["designer:ev__lingdong"] = "烈火幽魂",
  ["ev__wusasi"] = "乌萨斯战吼",
  [":ev__wusasi"] = "一名角色的弃牌阶段开始时，若其为其阵营中首名使用【杀】或明置身份牌的角色，你可令其选择一项：1.摸一张牌；2.其手牌上限于此回合内+1。若其满足以上两项条件或于此回合内杀死过角色，其依次执行选项1与2。",
  ["ev__wusasi1"] = "摸一张牌",
  ["ev__wusasi2"] = "手牌上限+1",

  ["$ev__wusasi1"] = "（俄）怕什么！",
  ["$ev__wusasi2"] = "（俄）你们一口气上吧！",
  ["$ev__wusasi3"] = "（俄）力量与荣耀！",
  ["$ev__wusasi4"] = "（俄）胜利与死亡！",
  ["~ev__lingdong"] = "（俄）丢人，你马上给我退出战场！",
}

local Reines = General(extension, "ev__reines", "ev", 3, 3, General.Female)

local yuelingsuiye_trigger = fk.CreateTriggerSkill{
  name = "#yuelingsuiye",
  anim_type = "defensive",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish    
    else
      return player:hasSkill(self) and data.card and data.card.trueName == "slash"
      and table.contains(player:getTableMark(self.name), target.id)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local targets = table.map(table.filter(player.room.alive_players, function (p)
        return player:inMyAttackRange(p) end), Util.IdMapper)
      if #targets > 0 then
        local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#yuelingsuiye-choose", self.name, true)
        if #tos > 0 then
          self.cost_data = tos[1]
          return true
        end
      end
    else
      local cards = table.filter(player:getCardIds("h"), function (id)
        return Fk:getCardById(id).type == Card.TypeTrick and Fk:getCardById(id):getMark("@@shown-inhand") == 0
      end)
      local card = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), "#yuelingsuiye-show::"..target.id)
      if #card > 0 then
        self.cost_data = card
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local to = room:getPlayerById(self.cost_data)
      local mark = player:getTableMark(self.name)
      table.insertIfNeed(mark, player.id)
      table.insertIfNeed(mark, self.cost_data)
      room:setPlayerMark(player, self.name, mark)
      room:addPlayerMark(to, "@@yuelingsuiye")  
    else
      EV.OpenCards(room, player, self.cost_data, self.name)
      data.damage = data.damage - 1
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(player.room.alive_players) do
      if table.contains(player:getTableMark(self.name), p.id) and p:getMark("@@yuelingsuiye") > 0 then
        room:setPlayerMark(p, "@@yuelingsuiye", 0)
      end
    end
    room:setPlayerMark(player, self.name, 0)
  end,
}

local yuelingsuiye = fk.CreateViewAsSkill{
  name = "yuelingsuiye",
  anim_type = "offensive",
  pattern = "slash",
  prompt = '你可重铸一张明置魔法牌，视为使用或打出【杀】',
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeTrick and Fk:getCardById(to_select):getMark("@@shown-inhand") > 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("slash")
    card:setMark(self.name, cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local put = use.card:getMark(self.name)
    if put ~= 0 and table.contains(player:getCardIds("he"), put) then
      room:recastCard(put, player, self.name)
    end
    room:setCardMark(use.card, self.name, 0)
  end,
}

local hunyuanyizhen = fk.CreateTriggerSkill{
  name = "hunyuanyizhen",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and not player:isNude() and not target:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 1, true, self.name, true, ".", "#hunyuanyizhen::"..target.id)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCard(target, 1, 1, true, self.name, false)
    if #card > 0 then
      table.insert(self.cost_data, card[1])
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true)
      if Fk:getCardById(self.cost_data[1]).type == Fk:getCardById(card[1]).type then
        room:drawCards(target, 1, self.name)
      else
        room:drawCards(player, 1, self.name)
      end
    end
  end
}

yuelingsuiye:addRelatedSkill(yuelingsuiye_trigger)
Reines:addSkill(yuelingsuiye)
Reines:addSkill(hunyuanyizhen)

Fk:loadTranslationTable{
  ["ev__reines"] = "莱妮丝",
  ["designer:ev__reines"] = "冰茶",
  ["yuelingsuiye"] = "月灵髓液",
  ["#yuelingsuiye"] = "月灵髓液",
  ["@@yuelingsuiye"] = "月灵髓液",
  ["#yuelingsuiye-choose"] = "你可选择一名你攻击范围内的角色",
  ["#yuelingsuiye-show"] = "你可明置一张魔法令%dest受到的伤害-1",
  [":yuelingsuiye"] = "结束阶段，你可选择一名你攻击范围内的角色；若如此做，直至你的下回合开始，当你或其受到【杀】造成的伤害时，你可明置一张魔法牌，令此伤害-1。你可重铸一张明置魔法牌，视为使用或打出【杀】。",
  ["hunyuanyizhen"] = "混元一阵",
  ["#hunyuanyizhen"] = "你可令你与%dest同时弃置一张牌",
  [":hunyuanyizhen"] = "其他角色的回合结束时，若你与其均有牌，你可令你与其同时弃置一张牌；若这两张牌的类别：相同，其摸一张牌；不同，你摸一张牌。",
}

return extension